/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ocumed.teams.teamb.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author apr3455
 */
public class WarteschlangeCellRender extends DefaultTableCellRenderer {
  Color m_color = null;  
  WarteschlangeModel m_tableModel = null;
  boolean test = false;
  JPanel[][] m_panels = null;
  JLabel[][] m_labels = null;
  Integer m_columnCount;
  Integer m_rowCount;
  
  public WarteschlangeCellRender(WarteschlangeModel tableModel){
      m_tableModel = tableModel;
      init();
  }
  
  public void init(){
      int row = m_tableModel.getRowCount();
      int col = m_tableModel.getColumnCount();
      m_columnCount = col;
      m_rowCount = row;
      m_tableModel.getColumnCount();
      m_labels = new JLabel[row][col];
      m_panels = new JPanel[row][col];
      for(int i = 0; i  < row; i++){
          for(int e = 0; e < col; e++){
              m_labels[i][e] = new JLabel((String) m_tableModel.getValueAt(i, e));
              m_panels[i][e] = new JPanel();
              m_panels[i][e].add(m_labels[i][e]);
              m_panels[i][e].setLayout(new GridLayout(1,0));
          }
      }
  }
  
  @Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
      String v = " " + (String) value;
      
      if(column >= m_columnCount - 1 || row >= m_rowCount - 1){
          init();
      }
      
      m_labels[row][column].setText(v);
      if(isSelected == false){
          if(!value.equals("")) {
              m_panels[row][column].setBackground(new Color(222,222,222));
          } else {
              m_panels[row][column].setBackground(new Color(255,255,255));
          }
      } else if(!value.equals("")) {
          m_panels[row][column].setBackground(new Color(200,200,200));
      }
      return m_panels[row][column];
  }
}
